package com.xlx.openLink.entity.baseenity;



import com.xlx.openLink.entity.device.DeviceInfo;
import com.xlx.openLink.entity.device.PortInfo;

import java.io.Serializable;

/**
 * @author seven
 * @create 2019-06-17 13:36
 **/
public class LinkInfo implements Serializable {
    public DeviceInfo startDevice;
    public DeviceInfo endDevice;
    public PortInfo startPortInfo;
    public PortInfo endPortInfo;
    public int startPort = -1;
    public int endPort = -1;
    public String linkType;
    public static final int UnknownPort = -1;
    public static final String LinkTypeInbound = "";
    public static final String LinkTypeOutbound = "";

    public LinkInfo() {
        this.linkType = LinkTypeInbound;
    }

    public String toString() {
        return this.linkType + "," + this.startDevice + ",端口:" + (this.startPort == -1 ? "未知": this.startPort) + ",MAC:" + this.startDevice.getDeviceMAC() + " <------> " + this.endDevice + ",端口：" + (this.endPort == -1 ? ",未知": this.endPort) + ",MAC:" + this.endDevice.getDeviceMAC();
    }

    public boolean equals(Object var1) {
        if (var1 instanceof LinkInfo) {
            LinkInfo var2 = (LinkInfo) var1;
            if (this.startDevice.equals(var2.startDevice) && this.startPort == var2.startPort && this.endDevice.equals(var2.endDevice) && this.endPort == var2.endPort) {
                return true;
            }
        }

        return false;
    }

    public int checkFuzzyOrAccurate(LinkInfo var1) {
        if (this.equals(var1)) {
            return 0;
        } else if (var1.startDevice.equals(this.startDevice) && var1.endDevice.equals(this.endDevice)) {
            int var2 = var1.startPort;
            int var3 = var1.endPort;
            if (-1 == this.startPort && -1 == this.endPort) {
                return 1;
            } else if (-1 == this.startPort && -1 != var2 && var3 == this.endPort) {
                return 1;
            } else if (-1 == this.endPort && -1 != var3 && var2 == this.startPort) {
                return 1;
            } else if (-1 == var2 && -1 == var3) {
                return 0;
            } else {
                if (-1 != this.startPort && -1 != this.endPort) {
                    if (this.startPort == var2 && -1 == var3) {
                        return 0;
                    }

                    if (this.endPort == var3 && -1 == var2) {
                        return 0;
                    }
                }

                return -1;
            }
        } else {
            return -1;
        }
    }
}

